package com.mes.task.dao;

import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.mes.common.dao.BasicDao;
import com.mes.task.dao.iface.IAssignmentWorkCenterDao;
import com.mes.task.domain.AssignmentWorkCenter;

@Repository
public class AssignmentWorkCenterDao extends BasicDao<AssignmentWorkCenter> implements IAssignmentWorkCenterDao {

private final static Log log = LogFactory.getLog(AssignmentWorkCenterDao.class);
	
	@Override
	public List<AssignmentWorkCenter> getAssignmentWorkCenters(String deptUid,
			Date fromDate, Date toDate, Integer from, Integer size) {
		List list=null;
		try {
			Session session=this.getSession();
			StringBuilder hql=new StringBuilder();
			hql.append("from "+ AssignmentWorkCenter.class.getName() +" where ");
			hql.append( " createTime between ? and ? ");
			hql.append("  and operationTask.parentTask.masterShopUid=? order by createTime");
			Query query = session.createQuery(hql.toString());
			query.setTimestamp(0, fromDate);
			query.setTimestamp(1, toDate);
			query.setString(2, deptUid);
			if (from != null && size != null && from >= 0
					&& size >= 0) {
				query.setFirstResult(from);
				query.setMaxResults(size);
				
			}
			list = query.list();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	
}
